package com.jucai.pppeiyouclient.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jucai.pppeiyouclient.MainActivity;
import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.base.BaseActivity;
import com.jucai.pppeiyouclient.base.QuickFragmentAdapter;
import com.jucai.pppeiyouclient.utils.ActivityCollector;
import com.jucai.pppeiyouclient.utils.ScreenUtil;
import com.jucai.pppeiyouclient.view.fragment.MerchantApplyFragment;
import com.jucai.pppeiyouclient.view.fragment.MerchantEvaluateFragment;
import com.jucai.pppeiyouclient.view.fragment.MerchantRefundFragment;

import java.util.ArrayList;
import java.util.List;

public class MerchantServiceActivity extends BaseActivity {
    private TabLayout merchantServiceTab;
    private ViewPager merchantServiceVp;
    private QuickFragmentAdapter<Fragment> fragmentAdapter;
    private List<Fragment> fragments = new ArrayList<>();
    private String[] titles = new String[]{"待使用", "已使用", "已完成"};
    private int pagePosition;
    private LinearLayout linearLayout;

    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_merchant_service);

        fragments.add(new MerchantApplyFragment());
        fragments.add(new MerchantEvaluateFragment());
        fragments.add(new MerchantRefundFragment());

        fragmentAdapter = new QuickFragmentAdapter<>(getSupportFragmentManager(), fragments, titles);
        ((TextView) findViewById(R.id.common_title_text)).setText("商家服务");
        merchantServiceTab = (TabLayout) findViewById(R.id.merchant_service_tab);
        merchantServiceVp = (ViewPager) findViewById(R.id.merchant_service_vp);
        merchantServiceVp.setAdapter(fragmentAdapter);
        merchantServiceTab.setupWithViewPager(merchantServiceVp);

        linearLayout = (LinearLayout) merchantServiceTab.getChildAt(0);
        linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        linearLayout.setDividerDrawable(ContextCompat.getDrawable(this, R.drawable.shape_vertical_divider_gray));
        linearLayout.setDividerPadding(ScreenUtil.dip2px(MerchantServiceActivity.this, 15));

    }

    @Override
    protected void initData() {
        pagePosition = getIntent().getIntExtra("page_position", 0);
        switch (pagePosition) {
            case 0:
                merchantServiceVp.setCurrentItem(0);
                break;
            case 1:
                merchantServiceVp.setCurrentItem(1);
                break;
            case 2:
                merchantServiceVp.setCurrentItem(2);
                break;
            default:
                break;
        }

    }

    @Override
    protected void loadNetData() {

    }

    @Override
    protected void setListener() {
        findViewById(R.id.common_back).setOnClickListener(this);
        findViewById(R.id.common_home_back).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.common_back:
                ActivityCollector.removeActivity(this);
                break;

            case R.id.common_home_back:
                startActivity(new Intent(MerchantServiceActivity.this, MainActivity.class));
                ActivityCollector.removeActivity(this);
                break;
        }
    }
}
